package com.sanhuo.idms.utils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class EnumUtil {

    public static String getMsg(Class clazz, Integer code) {
        Object[] objects = clazz.getEnumConstants();
        try {

            Method getCode = clazz.getMethod("getCode");
            Method getMsg = clazz.getMethod("getMsg");
            for (Object obj : objects) {
                if (getCode.invoke(obj) == code) {
                    return getMsg.invoke(obj).toString();
                }
            }
            return null;
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    }
}
